#include "Figure.h"

Figure::Figure()
: Component("Figure")
{
}

Figure::~Figure(void)
{
    //delete m_mManager;
    //delete m_fManager;
    //delete m_tManager;
}

void Figure::addedToObject()
{
    requestMessage("InitFight",&Figure::Init);
    requestMessage("RenderFigure",&Figure::RenderFigure);
    //requestMessage("PutFigure",&Figure::AddFigureToWorld);
    requestMessage("CurActFig",&Figure::UpdateCurrentActionFigure);
    requestMessage("ClickedMoveMenu",&Figure::PreFigureMove);
    requestMessage("FigureMove",&Figure::FigureMove);
}

void Figure::Init(const Message &msg)
{
    /*
    m_mManager=new ModelManager;
    m_fManager=new FigureManager;
    m_tManager=new TextureManager;
    AnimManager* aManager=new AnimManager(m_mManager,m_fManager,m_tManager);		
    addLocalComponent(aManager);*/
    sendMessage("LoadFigure");
    LoadAnim();
}



void Figure::FigureMove(const Message & msg)
{
    /*World* w=(World*)msg.sender;
    WorldPoint pos=boost::any_cast<WorldPoint>(msg.p);
    vector<boost::any> any;
    any.push_back(pos);
    any.push_back(m_fManager->m_data[m_curFid].pos);

    sendMessage("AnimFigureMove",m_fManager->m_data[m_curFid].fid);
    w->SetFigureMove(m_fManager->m_data[m_curFid].pos);
    m_fManager->m_data[m_curFid].pos=pos;*/
}

void Figure::PreFigureMove(const Message & msg)
{
    //sendMessage("RenderMoveCell",m_fManager->m_data[m_curFid]);
}

void Figure::UpdateCurrentActionFigure(const Message & msg)
{
    /*int32 fid=boost::any_cast<int32>(msg.p);
    for(vector<FIGURE>::iterator iter=m_fManager->m_data.begin();iter<m_fManager->m_data.end();iter++)
    {
    if(iter->fid==fid)
    {
    m_curFid=iter->id;
    }
    }*/
}

void Figure::AddModel(int32 id,char* name,char* fname)
{
    /*MSG_MODEL mm;
    mm.id=id;
    mm.name=name;
    mm.fname=fname;

    sendLocalMessage("LoadModel",mm);*/
}

/*bool Figure::AddFigure(int32 id, int32 mid, const char* name, int32 x, int32 y, FACE f,FIGURE_ATTRIBUTE fa)
{

}*/

/*void Figure::AddFigureToWorld(const Message & msg)
{
for(vector<FIGURE>::iterator iter=m_fManager->m_data.begin();iter<m_fManager->m_data.end();iter++)
{
FIG_POS fp;
fp.fid=iter->fid;
fp.x=iter->pos.x;
fp.y=iter->pos.y;
sendMessage("AddFigureInWorld",&fp);
}
}*/

int32 Figure::AddTexture(char* name, LPDIRECT3DTEXTURE9 tex)
{
    //return m_tManager->AddObj(name,tex);
    return 0;
}

/*bool Figure::AddModel(int32 mid, int32 tid, char* name, Model* model)
{
return m_mManager->AddObj(mid,tid,name,model);
}
*/

bool Figure::LoadAnim()
{
    sendMessage("LoadAnim",0);
    return true;
}

void Figure::RenderFigure(const Message & msg)
{
    /*RenderEngine* re=(RenderEngine*)msg.sender;
    DWORD t=re->GetTick();
    sendMessage("RenderAnim",t);*/
}